<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false"%>
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>企业会员</title>
  <link href="<c:url value="/resources/easyui/themes/icon.css" />" rel="stylesheet" type="text/css" />
  <link href="<c:url value="/resources/easyui/themes/default/easyui.css" />" rel="stylesheet" type="text/css" />
  <script src="<c:url value="/resources/easyui/jquery-1.7.1.min.js" />"></script>
  <script src="<c:url value="/resources/easyui/jquery.easyui.min.js" />"></script>
  <script type="text/javascript" src="<c:url value="/resources/easyui/locale/easyui-lang-zh_CN.js" />"></script>
</head>

<script>
    $(function(){

    	var url = '<c:url value="/admin/member/query?type=company&page=1&pageSize=10" />';
    	
		$('#enterpriseTable').datagrid({
			title:'用户一览',
			iconCls:'icon-edit',
			width:800,
			height:500,
			nowrap: false,
			striped: true,
			fit: true,
			url: url,
			sortName: 'id',
			sortOrder: 'name',
			idField:'id',
			frozenColumns:[[
                {field:'ck',checkbox:true},
                {field:'status',title:'用户状态',width:80},
                {field:'username',title:'注册用户',width:120, sortable:true}
			]],
			columns:[
			[
                //{field:'status',title:'用户状态',width:120},
				//{field:'username',title:'注册用户',width:120},
				{field:'mobile',title:'移动电话',width:100},
				{field:'name',title:'公司名称',width:120},
				{field:'type',title:'公司类型',width:120},
				{field:'biz',title:'所属行业',width:80},
				{field:'tel',title:'公司电话',width:120},
				{field:'fax',title:'公司传真',width:120},
				{field:'address',title:'地址',width:300,rowspan:1,sortable:true}//,
				//{field:'opt',title:'Operation',width:100,align:'center', rowspan:1,
					//formatter:function(value,rec){
						//return '<span style="color:red">Edit Delete</span>';
					//}
				//}
			]],
			pagination:true,
			rownumbers:false,
			toolbar:[
			     //{text:'添加新用户',
			    	//iconCls:'icon-add',
			    	//handler:function(){
			    	//}
			     //},
			     //'-',
			     {
			     	text:'批量启用',
			     	iconCls:'icon-ok',
			     	handler:function(){
				     	batchOperation('enable');
			     	}
			     }
			     ,'-',
			     {
			     	text:'批量禁用',
			     	iconCls:'icon-cancel',
			     	handler:function(){
			    	 batchOperation('disable');
			     	}
				 }
			 ]
		});
			
	});

	function batchOperation(action){
		var selectedRecords = $('#enterpriseTable').datagrid("getSelections");
		if(selectedRecords.length == 0){
			$.messager.alert('提示','请选择用户');
			return;
		}
		//alert(selectedRecords);
		var ids = [];
		var names = [];
		$.each(selectedRecords, function(index, value){
			ids.push(value.id);
			names.push(value.username);
		});
		//alert(ids.join(":"));
		if(action=='disable'){
			$.messager.confirm('禁用提示', '你确定禁用下列用户吗?<br/>'+names.join(','), function(r){  
			    if (r){
			        var url = '<c:url value="/admin/member/update" />?membertype=Company&memberaction=Disable'+'&ids='+ids.join(',');
			        changeStatus(url);
			    }
			});
		}else if (action=='enable'){
			$.messager.confirm('启用提示', '你确定启用下列用户吗?<br/>'+names.join(','), function(r){  
			    if (r){
			        var url = '<c:url value="/admin/member/update" />?membertype=Company&memberaction=Enable'+'&ids='+ids.join(',');
			        changeStatus(url);
			    }
			});
		}
	}

	function changeStatus(url){
		$.ajax({
			async : false,
			cache:false,
			type: 'POST',
			dataType : "json",
			url:url,//请求的action路径
			error: function () {//请求失败处理函数
				alert('请求失败');
			},success:function(data){
				if(data!=null){//返回异常信息
					$.messager.alert('错误提示',data.errorMsg,'error');
				}else{
					$.messager.alert('成功提示','操作成功');
				}
				clearSelection();
				reloadTable();
			}
		});
	}
	
	function clearSelection(){
		$('#enterpriseTable').datagrid('clearSelections');
	}
	
	function reloadTable(){
		$('#enterpriseTable').datagrid('reload');
	}
</script>
	
<body class="easyui-layout">
  <div region="center">
    <table id="enterpriseTable"></table>
  <div region="center">
</body>
</html>